# -*- coding: utf-8 -*-
"""
@author: Trae
@contact: traetai@gmail.com
@software: TraeAI
@file: config_loader.py
@time: 2024/7/29 16:21
@desc: 加载YAML配置文件
"""
import yaml
from pathlib import Path

def load_config(config_path: str = 'configs/config.yaml') -> dict:
    """
    加载并解析YAML配置文件。

    Args:
        config_path (str): 配置文件的路径。

    Returns:
        dict: 包含配置信息的字典。
    """
    path = Path(config_path)
    if not path.is_file():
        raise FileNotFoundError(f"Configuration file not found at: {config_path}")

    with open(path, 'r', encoding='utf-8') as f:
        config = yaml.safe_load(f)

    return config

if __name__ == '__main__':
    # 这是一个测试该模块功能的示例
    try:
        #config = load_config('../../configs/config.yaml')
        config = load_config('E:\DEV\gitproject\yolo\configs\config.yaml')
        print("配置加载成功:")
        import json
        print(json.dumps(config, indent=4))
    except FileNotFoundError as e:
        print(e)